<template>
	<!--选择组织-->
	<view class="orgbox">
		<view class="orgbox-top">
			<text>请选择租户进入</text>
		</view>
		<view class="orglist" v-if="data.orgList.length > 0">
			<view class="orglist-item" :class="currentIndex == index ? 'active' : ''" v-for="(list,index) in data.orgList" :key="index" @click="handleOrg(list,index)">
				<text class="iconfont icon-zuhu" style="margin-right:24rpx;"></text>
				<text class="orgcontent">{{list.companyName}}</text>
			</view>
		</view>
	</view>
	<view class="handlebtnbox" @click="handleLogin">
		<view class="handlebtn">
			<text>确认</text>
		</view>
	</view>
</template>

<script setup>
import {ref, reactive, } from 'vue'
import { onLoad} from '@dcloudio/uni-app'
import {getTenants} from '@/api/login.js'
	let currentIndex = ref('')
	const data = reactive({
		orgList:[]
	})
	onLoad(()=>{
		//获取租户列表
		getOrgList()
	})
	//获取租户列表
	const getOrgList = () =>{
		let paramsObj = {
			USER_ID:uni.getStorageSync('userId')
		}
		getTenants(paramsObj).then(res=>{
			if(res.data.code == 0){
				data.orgList = res.data.result
				uni.setStorageSync('tenantId',data.orgList[0].tenantId)
				uni.setStorageSync('companyName',data.orgList[0].companyName)
			}else{
				uni.showToast({
					title:res.data.msg,
					icon:'none'
				})
			}
		})
	}
	//点击组织
	const handleOrg = (val,index) =>{
		currentIndex.value = index
		uni.setStorageSync('tenantId',val.tenantId)
		uni.setStorageSync('companyName',val.companyName)
	}
	//确认登录
	const handleLogin = () =>{
		uni.switchTab({
			url:'/pages/ticketList/index'
		})
	}
</script>

<style lang="scss" scoped>
	.orgbox{
		padding:48rpx 32rpx;
		.orgbox-top{
			font-family: PingFangSC-Medium;
			font-weight: 500;
			font-size: 36rpx;
			color: #333333;
		}
		.orglist{
			padding-top:32rpx;
			.orglist-item{
				display: flex;
				align-items: center;
				padding:0 30rpx;
				margin-bottom:32rpx;
				height: 124rpx;
				background: #FFFFFF;
				border: 2rpx solid #fff;
				box-shadow: 0 0 16rpx 0 #296dfa29;
				border-radius: 16rpx;
				.orgcontent{
					width:500rpx;
					overflow: hidden;
					white-space: nowrap;
					text-overflow: ellipsis;
				}
			}
			.active{
				border: 2rpx solid #296DFA;
			}
		}
	}
	.handlebtnbox{
		position:fixed;
		left:0;
		bottom:0;
		width:100%;
		padding:32rpx 0;
		background: #FFFFFF;
		box-shadow: 0 2rpx 20rpx 0 #d1d1d145;
		.handlebtn{
			height: 80rpx;
			line-height: 80rpx;
			margin:0 32rpx;
			text-align:center;
			background: #296DFA;
			border-radius: 40rpx;
			font-family: PingFangSC-Regular;
			font-weight: 400;
			font-size: 32rpx;
			color: #fff;
		}
	}
</style>